package com.java.mybatis.service.impl;

import com.java.mybatis.dao.LocationDao;
import com.java.mybatis.entity.Location;
import com.java.mybatis.service.LocationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Location)表服务实现类
 *
 * @author makejava
 * @since 2021-01-15 17:10:28
 */
@Service("locationService")
public class LocationServiceImpl implements LocationService {
    @Resource
    private LocationDao locationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param locationId 主键
     * @return 实例对象
     */
    @Override
    public Location queryById(Integer locationId) {
        return this.locationDao.queryById(locationId);
    }

    /**
     * 货位报表
     * @return
     */
    @Override
    public List<Location> querySel() {
        List<Location> locationList = locationDao.querySel();
        return locationList;
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Location> queryAllByLimit(int offset, int limit) {
        return this.locationDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param location 实例对象
     * @return 实例对象
     */
    @Override
    public Location insert(Location location) {
        this.locationDao.insert(location);
        return location;
    }

    /**
     * 修改数据
     *
     * @param location 实例对象
     * @return 实例对象
     */
    @Override
    public Location update(Location location) {
        this.locationDao.update(location);
        return this.queryById(location.getLocationId());
    }

    /**
     * 通过主键删除数据
     *
     * @param locationId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer locationId) {
        return this.locationDao.deleteById(locationId) > 0;
    }


    /**
     * 根据货物id查询库位
     * @param goodId
     * @return
     */
    @Override
    public Location queryByGoodId(Integer goodId){
        return locationDao.queryByGoodId(goodId);
    }

    /**
     * 出库时 根据id修改库位的使用状态
     * @return
     */
    @Override
    public int updateLocationStateByLocationId(Integer locationId){
        return locationDao.updateLocationStateByLocationId(locationId);
    }
}